<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Diploma Sys</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="../bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="../bower_components/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="../dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="../dist/css/skins/_all-skins.min.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="../bower_components/morris.js/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="../bower_components/jvectormap/jquery-jvectormap.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="../bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="../bower_components/bootstrap-daterangepicker/daterangepicker.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Google Font -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

    <header class="main-header">
        <!-- Logo -->
        <a href="index.html" class="logo">
            <!-- mini logo for sidebar mini 50x50 pixels -->
            <span class="logo-mini"><b>A</b>LT</span>
            <!-- logo for regular state and mobile devices -->
            <span class="logo-lg"><b>Diploam</b>System</span>
        </a>
        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top">
            <!-- Sidebar toggle button-->
            <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
                <span class="sr-only">Toggle navigation</span>
            </a>

            <div class="navbar-custom-menu">
                <ul class="nav navbar-nav">
                    <!-- User Account: style can be found in dropdown.less -->
                    <li class="dropdown user user-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                            <img th:src="${User.getImage()}"  class="user-image" alt="User Image">
                            <span class="hidden-xs" th:text="${User.getName()}"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <!-- User image -->
                            <li class="user-header">
                                <img th:src="${User.getImage()}" class="img-circle" alt="User Image">

                                <p>
                                    <span th:text="${User.getName()}"></span>
                                    <small  th:text="'学历编号 ：'+${User.getEduHash()}"></small>
                                    <small  th:text="'认证时间 ：'+${User.getTime()}"></small>
                                </p>
                            </li>
                            <!--              <input id="LoginOrNologin" class="control-sidebar-subheading" value="Loginfalse" style="display: none"/>-->
                            <!-- Menu Footer-->
                            <li class="user-footer">
                                <div class="pull-right">
                                    <a class="btn btn-default btn-flat" id="Login" th:value="${Login}" th:text="${Login}"></a>
                                </div>
                            </li>
                        </ul>
                    </li>
                </ul>
            </div>
        </nav>
    </header>
    <!-- Left side column. contains the logo and sidebar -->
    <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">
            <!-- Sidebar user panel -->
            <div class="user-panel">
                <div class="pull-left image">
                    <img th:src="${User.getImage()}" class="img-circle" alt="User Image">
                    <!--          <img src="../static/dist/img/tourist.jpeg" class="img-circle" alt="User Image">-->
                </div>
                <div class="pull-left info">
                    <p th:value="${User.getName()}"></p>
                    <a href="#" id="Online"><i class="fa fa-circle text-success"></i> Online</a>
                </div>
            </div>
            <!-- sidebar menu: : style can be found in sidebar.less -->
            <ul class="sidebar-menu" data-widget="tree">
                <li class="header">Diploma System for u</li>
                <li>
                <li class="treeview">
                    <a href="#">
                        <i class="glyphicon glyphicon-home"></i> <span>主 页</span>
                        <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
              </span>
                    </a>
                    <ul class="treeview-menu">
                        <li><a href="/"><i class="fa fa-circle-o"></i>用户大厅</a></li>
                        <li><a href="/student/search"><i class="fa fa-circle-o"></i>学历查询</a></li>
                    </ul>
                </li>
                <li class="treeview">
                    <a href="#">
                        <i class="glyphicon glyphicon-user"></i> <span>个人中心</span>
                        <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
              </span>
                    </a>
                    <ul class="treeview-menu">
                        <li><a href="/student/personal"><i class="fa fa-circle-o"></i>个人资料</a></li>
                        <li><a href="/student/apply"><i class="fa fa-circle-o"></i>申请学历</a></li>
                        <li><a href="/student/regist"><i class="fa fa-circle-o"></i>用户注册</a></li>
                        <li><a href="/student/revoke"><i class="fa fa-circle-o"></i>撤销学历</a></li>
                        <li><a href="/student/history"><i class="fa fa-circle-o"></i>撤销历史</a></li>
                    </ul>
                </li>
            </ul>
        </section>
        <!-- /.sidebar -->
    </aside>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                Diploma System
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 个人中心</a></li>
                <li class="active">个人资料</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <form action="javascript:void(0)" id="showStudent" role="form">
                <div class="form-group">
                    <label for="showStudentID">ID</label>
                    <input class="form-control" id="showStudentID" name="id" type="text" readonly="readonly" th:value="${User.getId()}"/>
                </div>
                <div class="form-group">
                    <label for="showStudentName">姓名</label>
                    <input class="form-control" id="showStudentName" name="name" type="text" th:value="${User.getName()}"/>
                </div>
                <div class="form-group">
                    <label for="showStudentSid">学号</label>
                    <input class="form-control" id="showStudentSid" name="sid" type="text" th:value="${User.getSid()}"/>
                </div>
                <div class="form-group">
                    <label for="showStudentPassword">密码</label>
                    <input class="form-control" id="showStudentPassword" name="password" type="text" th:value="${User.getPassword()}"/>
                </div>
                <div class="form-group">
                    <label for="showStudentSchool">学校</label>
                    <input class="form-control" id="showStudentSchool" name="school" readonly="readonly" type="text" th:value="${User.getSchool()}"/>
                </div>
                <div class="form-group">
                    <label for="showStudentMajor">专业</label>
                    <input class="form-control" id="showStudentMajor" name="major" readonly="readonly" type="text" th:value="${User.getMajor()}"/>
                </div>
                <div class="form-group">
                    <label for="showStudentEduType">学位</label>
                    <input class="form-control" id="showStudentEduType" name="eduType" readonly="readonly" type="text"  th:value="${User.getEduType()}"/>
                </div>
                <div class="form-group">
                    <label for="showStudentEduHash">学历编号</label>
                    <input class="form-control" id="showStudentEduHash" name="eduHash"  readonly="readonly" type="text" th:value="${User.getEduHash()}"/>
                </div>
                <div class="form-group">
                    <label for="showStudentTime">学历认证时间</label>
                    <input class="form-control" id="showStudentTime" name="time" readonly="readonly"  type="text" th:value="${User.getTime()}"/>
                </div>
                <div class="form-group">
                    <label for="showStudentImage" style="display:none">头像</label>
                    <input class="form-control" id="showStudentImage" name="image" type="text"  style="display:none" th:value="${User.getImage()}"/>
                </div>
            </form>
                <div class="form-group">
                    <label for="file0">头像</label>
                    <input type="file" id="file0">
                    <img src="" alt="" id="img0" width="100" />
                    <button id="updateimage" class="btn-default" >更改头像</button>
                </div>
            <div class="modal-footer">
                <button class="btn btn-success"  id="Update" type="button">Update</button>
            </div>
            <div class="modal-footer">
                <button class="btn btn-danger" data-toggle="modal"  data-target="#revokeModel" type="button">注销此用户</button>
            </div>
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>Version</b> 0.0.1
        </div>
        <strong>DiplomaSystem@wust 2020--毕业设计</strong> By Aiden.徐险
    </footer>
    <!--显示的模态框-->

    <div aria-hidden="true" class="modal fade" id="revokeModel" role="dialog" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button aria-hidden="true" class="close" data-dismiss="modal" type="button">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">注销确认：</h4>
                </div>
                <div class="modal-body">
                    <form action="javascript:void(0)" id="revokeStudent" role="form">
                        <div class="form-group">
                            <label for="StudentID">ID</label>
                            <input class="form-control" id="StudentID" name="id" readonly="readonly" th:value="${User.getId()}" type="text"/>
                        </div>
                        <div class="form-group">
                            <label for="StudentPassword">密码</label>
                            <input class="form-control" id="StudentPassword" name="password" type="password" />
                        </div>
                    </form>
                    <div class="modal-footer">
                        <button class="btn btn-warning" id="revokeSdu" type="button">确定</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- ./wrapper -->

<!-- jQuery 3 -->
<script src="../bower_components/jquery/dist/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="../bower_components/jquery-ui/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
    $.widget.bridge('uibutton', $.ui.button);
</script>
<!-- Bootstrap 3.3.7 -->
<script src="../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="../bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="../bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<!-- Morris.js charts -->
<script src="../bower_components/raphael/raphael.min.js"></script>
<!--<script src="../bower_components/morris.js/morris.min.js"></script>-->
<!-- Sparkline -->
<script src="../bower_components/jquery-sparkline/dist/jquery.sparkline.min.js"></script>
<!-- jvectormap -->
<script src="../plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="../plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<!-- jQuery Knob Chart -->
<script src="../bower_components/jquery-knob/dist/jquery.knob.min.js"></script>
<!-- daterangepicker -->
<script src="../bower_components/moment/min/moment.min.js"></script>
<script src="../bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
<!-- datepicker -->
<script src="../bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<!-- Bootstrap WYSIHTML5 -->
<script src="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<!-- Slimscroll -->
<script src="../bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="../bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="../dist/js/adminlte.min.js"></script>

<!-- AdminLTE for demo purposes -->
<script src="../dist/js/demo.js"></script>
<script>
    $(document).ready(function () {
        if ($("#Login").text()=="Login in"){
            $("#Login").attr("href","/student/login");
            $("#Online").attr("class","fa fa-circle text-danger");
            $("#Online").text("  OffLine");
        }
        else
            $("#Login").attr("href","/student/signOut");

        $("#img0").attr("src", $("#showStudentImage").val());


        $('#revokeSdu').click(function () {
            var revokeData = $("#revokeStudent").serializeArray();
            var data = "{";
            for (var i = 0; i < revokeData.length; i++) {
                var name = revokeData[i].name;
                var value = revokeData[i].value;
                data = data + "\"" + name + "\":\"" + value.trim() + "\",";
            }
            data = data.substring(0, data.length - 1);
            data = data + "}";
            console.log(data);
            $.ajax({
                url: "/student/revokeStu",
                contentType: 'application/json',
                dataType: "json",
                type: "post",
                data: data,
                success: function (status) {
                    if (status.code == 1) {
                        alert("revoke student success");
                        window.location.replace("/");
                    } else {
                        alert("revoke student failed");
                    }
                },
                error: function (data) {
                    alert("revoke student  ok");
                    window.location.replace("/");
                }
            });
        })
        $('#Update').click(function () {
            var updateData = $("#showStudent").serializeArray();
            var data = "{";
            for (var i = 0; i < updateData.length; i++) {
                var name = updateData[i].name;
                var value = updateData[i].value;
                data = data + "\"" + name + "\":\"" + value.trim() + "\",";
            }
            data = data.substring(0, data.length - 1);
            data = data + "}";
            console.log(data);
            $.ajax({
                url: "/student/personal",
                contentType: 'application/json',
                dataType: "json",
                type: "post",
                data: data,
                success: function (status) {
                    if (status.code == 1) {
                        alert("update success");
                        window.location.reload();
                    } else {
                        alert("update failed");
                    }
                },
                error: function (data) {
                    $('#updateModal').modal('hide');
                    alert("update ok");
                    window.location.reload();
                }
            });
        });

        var fileName1="";
        var filePath1="";
        var fileM = document.querySelector("#file0");
        $("#file0").change(function(){

            //获取文件对象，files是文件选取控件的属性，存储的是文件选取控件选取的文件对象，类型是一个数组
            var fileObj = fileM.files[0];
            //创建formdata对象，formData用来存储表单的数据，表单数据时以键值对形式存储的。
            var formData = new FormData();
            formData.append('file', fileObj);
            var objUrl = getObjectURL(this.files[0]) ;//获取文件信息
            if (objUrl) {
                $("#img0").attr("src", objUrl);
            }
        }) ;
        function getObjectURL(file) {
            var url = null;
            if (window.createObjectURL!=undefined) {
                url = window.createObjectURL(file) ;
            } else if (window.URL!=undefined) { // mozilla(firefox)
                url = window.URL.createObjectURL(file) ;
            } else if (window.webkitURL!=undefined) { // webkit or chrome
                url = window.webkitURL.createObjectURL(file) ;
            }
            return url ;
        }

        $('#updateimage').click(function () {
            //获取文件对象，files是文件选取控件的属性，存储的是文件选取控件选取的文件对象，类型是一个数组
            var fileObj = fileM.files[0];
            //创建formdata对象，formData用来存储表单的数据，表单数据时以键值对形式存储的。
            var formData = new FormData();
            formData.append('file', fileObj);
            $.ajax({
                url : "/student/upload",
                type : "post",
                dataType : "json",
                data : formData,
                async : false,
                cache : false,
                contentType : false,
                processData : false,
                success : function(data) {
                    fileName1 = data.fileName;
                    filePath1 = data.filePath;
                    console.log(fileName1);
                    console.log(filePath1);
                    window.location.reload();
                },
                error : function(data) {
                    window.location.reload();
                }

        });
        });

    })


</script>
</body>
</html>
